package cn.seqdata.jpa;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

@MappedSuperclass
public class JpaGeneratedObject extends JpaAuditableObject {
	private static final long serialVersionUID = 1L;

	public JpaGeneratedObject() {
		super();
	}

	public JpaGeneratedObject(Long id) {
		super(id);
	}

	public JpaGeneratedObject(Long id, String name) {
		super(id, name);
	}

	@Transient
	@JsonIgnore
	@Override
	public boolean isNew() {
		return null == getId();
	}

	@Id
	@Column(name = "id", unique = true, nullable = false)
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "seq_info")
	@TableGenerator(name = "seq_info", table = "sequence", allocationSize = 1, //
			pkColumnName = "seq_name", valueColumnName = "seq_number", pkColumnValue = "info")
	@Override
	public Long getId() {
		return super.id;
	}
}
